package com.wenbai.servicelightluxurystickers.controller;

import com.wenbai.servicelightluxurystickers.entity.StickManage;
import com.wenbai.servicelightluxurystickers.entity.dto.StickManageDTO;
import com.wenbai.servicelightluxurystickers.entity.dto.StickManageLoginDto;
import com.wenbai.servicelightluxurystickers.entity.vo.StickManageLoginVO;
import com.wenbai.servicelightluxurystickers.service.StickManageService;
import com.wenbai.servicelightluxurystickers.utils.Response;
import com.wenbai.servicelightluxurystickers.utils.TokenUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * 后台管理
 */
@RestController
@RequestMapping("/stick/manage")
@Slf4j
public class StickManageController {

    @Autowired
    private StickManageService stickManageService;

    /**
     * 登录
      * @param stickManageLoginDto
     * @return
     */
@PostMapping("/login")
public Response<StickManageLoginVO> login(@RequestBody StickManageLoginDto stickManageLoginDto){
    log.info("管理员登录；{}",stickManageLoginDto);

    StickManage manage = stickManageService.login(stickManageLoginDto);

    //登录成功后，生成jwt令牌
    String token = TokenUtils.token(manage.getAccount(), manage.getPassword_hash());

    StickManageLoginVO stickManageLoginVO = StickManageLoginVO.builder()
            .admin_id(manage.getAdmin_id())
            .account(manage.getAccount())
            .admin_nickname(manage.getAdmin_nickname())
            .admin_avatar(manage.getAdmin_avatar())
            .token(token)
            .build();

    return Response.success(stickManageLoginVO);
}

}
